#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 998244353;
typedef long long LL;

void solve(){
    int n,m,k;
    cin >> n >> m >> k;
    vector<vector<int>> arr(n + 10,vector<int>(m + 10));
    if(n % k == 0)
    {
        int ft = 1;
        int cnt = ft;
        for(int i = 1; i <= m; i ++)
        {
            for(int j = 1; j <= n; j ++)
            {
                arr[j][i] = ft;
                ft ++;
                if(ft == k + 1) ft = 1;
            }
            cnt ++;
            if(cnt == k + 1) cnt = 1;
            ft = cnt;
        }
    }
    else
    {
        int cnt = 1;
        for(int i = 1; i <= m; i ++)
        {
            for(int j = 1; j <= n; j ++)
            {
                arr[j][i] = cnt;
                cnt ++;
                if(cnt == k + 1) cnt = 1;
            }
        }
    }
    for(int i = 1;i <= n; i ++)
    {
        for(int j = 1; j <= m; j ++)
        {
            cout << arr[i][j] << ' ';
        }
        cout << endl;
    }
}

signed main(){
    int t = 1;
    cin >> t;
    while(t--)
    {
        solve();
    }
}


